package com.hmall.order.service.impl;

import com.hmall.feign.client.UserClient;
import com.hmall.order.mapper.OrderLogisticsMapper;
import com.hmall.order.pojo.OrderLogistics;
import com.hmall.order.service.OrderLogisticsService;
import com.hmall.user.pojo.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class OrderLogisticsServiceImpl implements OrderLogisticsService {
    String []company={
        "顺丰", "圆通", "申通"
    };
    @Autowired
    UserClient userClient;
    @Autowired
    OrderLogisticsMapper orderLogisticsMapper;
    @Override
    public void insertOrderLogistics(Long addressId, Long id) {
        OrderLogistics orderLogistics=new OrderLogistics();
        orderLogistics.setOrderId(id);
        orderLogistics.setLogisticsNumber(Math.random()*100+"");
        orderLogistics.setLogisticsCompany(company[1]);
      Address address=userClient.findAddressById(addressId,"6");
        orderLogistics.setContact(address.getContact());
        orderLogistics.setProvince(address.getProvince());
        orderLogistics.setMobile(address.getMobile());
        orderLogistics.setCity(address.getCity());
        orderLogistics.setStreet(address.getStreet());
        orderLogistics.setTown(address.getTown());
        orderLogistics.setCreateTime(new Date());
        orderLogisticsMapper.insert(orderLogistics);

    }
}
